home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / hplip / check.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  20.7 KB  |  743 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __version__ = '14.1'
  5. __title__ = 'Dependency/Version Check Utility'
  6. __mod__ = 'hp-check'
  7. __doc__ = "Check the existence and versions of HPLIP dependencies. (Run as 'python ./check.py' from the HPLIP tarball before installation.)"
  8. import sys
  9. import os
  10. import getopt
  11. import commands
  12. import re
  13. from base.g import *
  14. from base import utils, tui, models
  15. from installer import dcheck
  16. from installer.core_install import *
  17. device_avail = False
  18.  
  19. try:
  20.     from base import device, pml
  21. except ImportError:
  22.     log.debug('Device library is not avail.')
  23.  
  24. device_avail = True
  25. USAGE = [
  26.     (__doc__, '', 'name', True),
  27.     ('Usage: %s [OPTIONS]' % __mod__, '', 'summary', True),
  28.     utils.USAGE_OPTIONS,
  29.     ('Compile-time check:', '-c or --compile', 'option', False),
  30.     ('Run-time check:', '-r or --run', 'option', False),
  31.     ('Compile and run-time checks:', '-b or --both (default)', 'option', False),
  32.     utils.USAGE_LOGGING1,
  33.     utils.USAGE_LOGGING2,
  34.     utils.USAGE_LOGGING3,
  35.     utils.USAGE_LOGGING_PLAIN,
  36.     utils.USAGE_HELP,
  37.     utils.USAGE_NOTES,
  38.     ('1. For checking for the proper build environment for the HPLIP supplied tarball (.tar.gz or .run),', '', 'note', False),
  39.     ('use the --compile or --both switches.', '', 'note', False),
  40.     ('2. For checking for the proper runtime environment for a distro supplied package (.deb, .rpm, etc),', '', 'note', False),
  41.     ('use the --runtime switch.', '', 'note', False)]
  42.  
  43. def usage(typ = 'text'):
  44.     if typ == 'text':
  45.         utils.log_title(__title__, __version__)
  46.     
  47.     utils.format_text(USAGE, typ, __title__, __mod__, __version__)
  48.     sys.exit(0)
  49.  
  50. build_str = 'HPLIP will not build, install, and/or function properly without this dependency.'
  51. pat_deviceuri = re.compile('(.*):/(.*?)/(\\S*?)\\?(?:serial=(\\S*)|device=(\\S*)|ip=(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}[^&]*))(?:&port=(\\d))?', re.I)
  52. pat_cups_error_log = re.compile('^loglevel\\s?(debug|debug2|warn|info|error|none)', re.I)
  53.  
  54. def parseDeviceURI(device_uri):
  55.     m = pat_deviceuri.match(device_uri)
  56.     if m is None:
  57.         raise Error(ERROR_INVALID_DEVICE_URI)
  58.     m is None
  59.     if not m.group(1).lower():
  60.         pass
  61.     back_end = ''
  62.     is_hp = back_end in ('hp', 'hpfax', 'hpaio')
  63.     if not m.group(2).lower():
  64.         pass
  65.     bus = ''
  66.     if bus not in ('usb', 'net', 'bt', 'fw', 'par'):
  67.         raise Error(ERROR_INVALID_DEVICE_URI)
  68.     bus not in ('usb', 'net', 'bt', 'fw', 'par')
  69.     if not m.group(3):
  70.         pass
  71.     model = ''
  72.     if not m.group(4):
  73.         pass
  74.     serial = ''
  75.     if not m.group(5):
  76.         pass
  77.     dev_file = ''
  78.     if not m.group(6):
  79.         pass
  80.     host = ''
  81.     if not m.group(7):
  82.         pass
  83.     port = 1
  84.     if bus == 'net':
  85.         
  86.         try:
  87.             port = int(port)
  88.         except (ValueError, TypeError):
  89.             port = 1
  90.  
  91.         if port == 0:
  92.             port = 1
  93.         
  94.     
  95.     return (back_end, is_hp, bus, model, serial, dev_file, host, port)
  96.  
  97. num_errors = 0
  98. fmt = True
  99. overall_commands_to_run = []
  100. time_flag = DEPENDENCY_RUN_AND_COMPILE_TIME
  101.  
  102. try:
  103.     log.set_module(__mod__)
  104.     
  105.     try:
  106.         (opts, args) = getopt.getopt(sys.argv[1:], 'hl:gtcrb', [
  107.             'help',
  108.             'help-rest',
  109.             'help-man',
  110.             'help-desc',
  111.             'logging=',
  112.             'run',
  113.             'runtime',
  114.             'compile',
  115.             'both'])
  116.     except getopt.GetoptError:
  117.         e = None
  118.         log.error(e.msg)
  119.         usage()
  120.         sys.exit(1)
  121.  
  122.     if os.getenv('HPLIP_DEBUG'):
  123.         log.set_level('debug')
  124.     
  125.     log_level = 'info'
  126.     for o, a in opts:
  127.         if o in ('-h', '--help'):
  128.             usage()
  129.             continue
  130.         if o == '--help-rest':
  131.             usage('rest')
  132.             continue
  133.         if o == '--help-man':
  134.             usage('man')
  135.             continue
  136.         if o == '--help-desc':
  137.             print __doc__,
  138.             sys.exit(0)
  139.             continue
  140.         if o in ('-l', '--logging'):
  141.             log_level = a.lower().strip()
  142.             continue
  143.         if o == '-g':
  144.             log_level = 'debug'
  145.             continue
  146.         if o == '-t':
  147.             fmt = False
  148.             continue
  149.         if o in ('-c', '--compile'):
  150.             time_flag = DEPENDENCY_COMPILE_TIME
  151.             continue
  152.         if o in ('-r', '--runtime', '--run'):
  153.             time_flag = DEPENDENCY_RUN_TIME
  154.             continue
  155.         if o in ('-b', '--both'):
  156.             time_flag = DEPENDENCY_RUN_AND_COMPILE_TIME
  157.             continue
  158.     
  159.     if not log.set_level(log_level):
  160.         usage()
  161.     
  162.     if not fmt:
  163.         log.no_formatting()
  164.     
  165.     utils.log_title(__title__, __version__)
  166.     log.info(log.bold('Note: hp-check can be run in three modes:'))
  167.     for l in tui.format_paragraph('1. Compile-time check mode (-c or --compile): Use this mode before compiling the HPLIP supplied tarball (.tar.gz or .run) to determine if the proper dependencies are installed to successfully compile HPLIP.'):
  168.         log.info(l)
  169.     
  170.     for l in tui.format_paragraph('2. Run-time check mode (-r or --run): Use this mode to determine if a distro supplied package (.deb, .rpm, etc) or an already built HPLIP supplied tarball has the proper dependencies installed to successfully run.'):
  171.         log.info(l)
  172.     
  173.     for l in tui.format_paragraph('3. Both compile- and run-time check mode (-b or --both) (Default): This mode will check both of the above cases (both compile- and run-time dependencies).'):
  174.         log.info(l)
  175.     
  176.     log.info()
  177.     log_file = os.path.normpath('./hp-check.log')
  178.     log.info(log.bold('Saving output in log file: %s' % log_file))
  179.     log.debug('Log file=%s' % log_file)
  180.     if os.path.exists(log_file):
  181.         os.remove(log_file)
  182.     
  183.     log.set_logfile(log_file)
  184.     log.set_where(log.LOG_TO_CONSOLE_AND_FILE)
  185.     log.info('\nInitializing. Please wait...')
  186.     core = CoreInstall(MODE_CHECK)
  187.     core.init()
  188.     core.set_plugin_version()
  189.     tui.header('SYSTEM INFO')
  190.     log.info(log.bold('Basic system information:'))
  191.     log.info(core.sys_uname_info)
  192.     log.info()
  193.     log.info(log.bold('Distribution:'))
  194.     log.info('%s %s' % (core.distro_name, core.distro_version))
  195.     log.info(log.bold('\nHPOJ running?'))
  196.     if core.hpoj_present:
  197.         log.error('Yes, HPOJ is running. HPLIP is not compatible with HPOJ. To run HPLIP, please remove HPOJ.')
  198.         num_errors += 1
  199.     else:
  200.         log.info('No, HPOJ is not running (OK).')
  201.     log.info()
  202.     log.info(log.bold('Checking Python version...'))
  203.     ver = sys.version_info
  204.     log.debug('sys.version_info = %s' % repr(ver))
  205.     ver_maj = ver[0]
  206.     ver_min = ver[1]
  207.     ver_pat = ver[2]
  208.     if ver_maj == 2:
  209.         if ver_min >= 1:
  210.             log.info('OK, version %d.%d.%d installed' % ver[:3])
  211.         else:
  212.             log.error('Version %d.%d.%d installed. Please update to Python >= 2.1' % ver[:3])
  213.             sys.exit(1)
  214.     
  215.     if core.ui_toolkit == 'qt3':
  216.         log.info()
  217.         log.info(log.bold('Checking PyQt 3.x version...'))
  218.         
  219.         try:
  220.             import qt
  221.         except ImportError:
  222.             num_errors += 1
  223.             log.error('NOT FOUND OR FAILED TO LOAD!')
  224.  
  225.         qtMajor = int(qt.qVersion().split('.')[0])
  226.         if qtMajor < MINIMUM_QT_MAJOR_VER:
  227.             log.error('Incorrect version of Qt installed. Ver. 3.0.0 or greater required.')
  228.         else:
  229.             
  230.             try:
  231.                 pyqtVersion = qt.PYQT_VERSION_STR
  232.             except AttributeError:
  233.                 pyqtVersion = qt.PYQT_VERSION
  234.  
  235.             while pyqtVersion.count('.') < 2:
  236.                 pyqtVersion += '.0'
  237.             (maj_ver, min_ver, pat_ver) = pyqtVersion.split('.')
  238.             if pyqtVersion.find('snapshot') >= 0:
  239.                 log.error('A non-stable snapshot version of PyQt is installed (%s).' % pyqtVersion)
  240.                 num_errors += 1
  241.             else:
  242.                 
  243.                 try:
  244.                     maj_ver = int(maj_ver)
  245.                     min_ver = int(min_ver)
  246.                     pat_ver = int(pat_ver)
  247.                 except ValueError:
  248.                     (maj_ver, min_ver, pat_ver) = (0, 0, 0)
  249.  
  250.                 if (maj_ver < MINIMUM_PYQT_MAJOR_VER or maj_ver == MINIMUM_PYQT_MAJOR_VER) and min_ver < MINIMUM_PYQT_MINOR_VER:
  251.                     num_errors += 1
  252.                     log.error('HPLIP may not function properly with the version of PyQt that is installed (%d.%d.%d).' % (maj_ver, min_ver, pat_ver))
  253.                     log.error('Ver. %d.%d or greater required.' % (MINIMUM_PYQT_MAJOR_VER, MINIMUM_PYQT_MINOR_VER))
  254.                 else:
  255.                     log.info('OK, version %d.%d installed.' % (maj_ver, min_ver))
  256.         del qt
  257.     else:
  258.         log.info()
  259.         log.info(log.bold('Checking PyQt 4.x version...'))
  260.         
  261.         try:
  262.             import PyQt4
  263.         except ImportError:
  264.             num_errors += 1
  265.             log.error('NOT FOUND OR FAILED TO LOAD!')
  266.  
  267.         from PyQt4 import QtCore
  268.         log.info('OK, version %s installed.' % QtCore.PYQT_VERSION_STR)
  269.     log.info()
  270.     log.info(log.bold('Checking for CUPS...'))
  271.     cups_ok = True
  272.     (status, output) = utils.run('lpstat -r')
  273.     if status == 0:
  274.         log.info('Status: %s' % output.strip())
  275.     else:
  276.         log.error('Status: (Not available. CUPS may not be installed or not running.)')
  277.         cups_ok = False
  278.         num_errors += 1
  279.     if cups_ok:
  280.         (status, output) = utils.run('cups-config --version')
  281.         if status == 0:
  282.             log.info('Version: %s' % output.strip())
  283.         else:
  284.             log.error('Version: (Not available. CUPS may not be installed or not running.)')
  285.             cups_ok = False
  286.             num_errors += 1
  287.     
  288.     if cups_ok:
  289.         cups_conf = '/etc/cups/cupsd.conf'
  290.         
  291.         try:
  292.             f = file(cups_conf, 'r')
  293.         except (IOError, OSError):
  294.             log.warn('%s file not found or not accessible.' % cups_conf)
  295.  
  296.         for l in f:
  297.             m = pat_cups_error_log.match(l)
  298.             if m is not None:
  299.                 level = m.group(1).lower()
  300.                 log.info('error_log is set to level: %s' % level)
  301.                 break
  302.                 continue
  303.         
  304.     
  305.     log.info()
  306.     log.info(log.bold('Checking for dbus/python-dbus...'))
  307.     if dcheck.check_ps([
  308.         'dbus-daemon']):
  309.         log.info('dbus daemon is running.')
  310.     else:
  311.         log.warn('dbus daemon is not running.')
  312.     
  313.     try:
  314.         import dbus
  315.         
  316.         try:
  317.             log.info('python-dbus version: %s' % dbus.__version__)
  318.         except AttributeError:
  319.             
  320.             try:
  321.                 '.'.join([] % []([ str(x) for x in dbus.version ]))
  322.             except AttributeError:
  323.                 log.warn('python-dbus imported OK, but unknown version.')
  324.             except:
  325.                 None<EXCEPTION MATCH>AttributeError
  326.             
  327.  
  328.             None<EXCEPTION MATCH>AttributeError
  329.  
  330.     except ImportError:
  331.         log.warn('python-dbus not installed.')
  332.  
  333.     log.info()
  334.     if time_flag == DEPENDENCY_RUN_AND_COMPILE_TIME:
  335.         tui.header('COMPILE AND RUNTIME DEPENDENCIES')
  336.         log.note('To check for compile-time only dependencies, re-run hp-check with the -c parameter (ie, hp-check -c).')
  337.         log.note('To check for run-time only dependencies, re-run hp-check with the -r parameter (ie, hp-check -r).')
  338.     elif time_flag == DEPENDENCY_COMPILE_TIME:
  339.         tui.header('COMPILE TIME DEPENDENCIES')
  340.     elif time_flag == DEPENDENCY_RUN_TIME:
  341.         tui.header('RUNTIME DEPENDENCIES')
  342.     
  343.     log.info()
  344.     dd = core.dependencies.keys()
  345.     dd.sort()
  346.     for d in dd:
  347.         if (d == 'pyqt' or core.ui_toolkit != 'qt3' or d == 'pyqt4') and core.ui_toolkit != 'qt4':
  348.             continue
  349.         
  350.         log.debug('***')
  351.         if time_flag == DEPENDENCY_RUN_AND_COMPILE_TIME or time_flag == core.dependencies[d][4]:
  352.             log.info(log.bold('Checking for dependency: %s...' % core.dependencies[d][2]))
  353.             if core.have_dependencies[d]:
  354.                 log.info('OK, found.')
  355.             else:
  356.                 num_errors += 1
  357.                 if core.dependencies[d][4] == DEPENDENCY_RUN_AND_COMPILE_TIME:
  358.                     s = ''
  359.                 elif core.dependencies[d][4] == DEPENDENCY_COMPILE_TIME:
  360.                     s = '/COMPILE TIME ONLY'
  361.                 elif core.dependencies[d][4] == DEPENDENCY_RUN_TIME:
  362.                     s = '/RUNTIME ONLY'
  363.                 
  364.                 if core.dependencies[d][0]:
  365.                     log.error('NOT FOUND! This is a REQUIRED%s dependency. Please make sure that this dependency is installed before installing or running HPLIP.' % s)
  366.                 else:
  367.                     log.warn('NOT FOUND! This is an OPTIONAL%s dependency. Some HPLIP functionality may not function properly.' % s)
  368.                 if core.distro_supported():
  369.                     (packages_to_install, commands) = core.get_dependency_data(d)
  370.                     commands_to_run = []
  371.                     if packages_to_install:
  372.                         package_mgr_cmd = core.get_distro_data('package_mgr_cmd')
  373.                         if package_mgr_cmd:
  374.                             packages_to_install = ' '.join(packages_to_install)
  375.                             commands_to_run.append(utils.cat(package_mgr_cmd))
  376.                         
  377.                     
  378.                     if commands:
  379.                         commands_to_run.extend(commands)
  380.                     
  381.                     overall_commands_to_run.extend(commands_to_run)
  382.                     if len(commands_to_run) == 1:
  383.                         log.info('To install this dependency, execute this command:')
  384.                         log.info(commands_to_run[0])
  385.                     elif len(commands_to_run) > 1:
  386.                         log.info('To install this dependency, execute these commands:')
  387.                         for c in commands_to_run:
  388.                             log.info(c)
  389.                         
  390.                     
  391.                 
  392.             log.info()
  393.             continue
  394.     
  395.     if time_flag in (DEPENDENCY_RUN_TIME, DEPENDENCY_RUN_AND_COMPILE_TIME):
  396.         tui.header('HPLIP INSTALLATION')
  397.         scanning_enabled = utils.to_bool(sys_conf.get('configure', 'scanner-build', '0'))
  398.         log.info()
  399.         log.info(log.bold('Currently installed HPLIP version...'))
  400.         v = sys_conf.get('hplip', 'version')
  401.         home = sys_conf.get('dirs', 'home')
  402.         if v:
  403.             log.info("HPLIP %s currently installed in '%s'." % (v, home))
  404.             log.info()
  405.             log.info(log.bold("Current contents of '/etc/hp/hplip.conf' file:"))
  406.             
  407.             try:
  408.                 output = file('/etc/hp/hplip.conf', 'r').read()
  409.             except (IOError, OSError):
  410.                 e = None
  411.                 log.error('Could not access file: %s' % e.strerror)
  412.  
  413.             log.info(output)
  414.             log.info()
  415.             log.info(log.bold("Current contents of '~/.hplip/hplip.conf' file:"))
  416.             
  417.             try:
  418.                 output = file(os.path.expanduser('~/.hplip/hplip.conf'), 'r').read()
  419.             except (IOError, OSError):
  420.                 e = None
  421.                 log.error('Could not access file: %s' % e.strerror)
  422.  
  423.             log.info(output)
  424.         else:
  425.             log.info('Not found.')
  426.         if device_avail:
  427.             if prop.par_build:
  428.                 tui.header('DISCOVERED PARALLEL DEVICES')
  429.                 devices = device.probeDevices([
  430.                     'par'])
  431.                 if devices:
  432.                     f = tui.Formatter()
  433.                     f.header = ('Device URI', 'Model')
  434.                     for d, dd in devices.items():
  435.                         f.add((d, dd[0]))
  436.                     
  437.                     f.output()
  438.                 else:
  439.                     log.info('No devices found.')
  440.                     if not core.have_dependencies['ppdev']:
  441.                         log.error("'ppdev' kernel module not loaded.")
  442.                     
  443.             
  444.             if prop.usb_build:
  445.                 tui.header('DISCOVERED USB DEVICES')
  446.                 devices = device.probeDevices([
  447.                     'usb'])
  448.                 if devices:
  449.                     f = tui.Formatter()
  450.                     f.header = ('Device URI', 'Model')
  451.                     for d, dd in devices.items():
  452.                         f.add((d, dd[0]))
  453.                     
  454.                     f.output()
  455.                 else:
  456.                     log.info('No devices found.')
  457.             
  458.         
  459.         tui.header('INSTALLED CUPS PRINTER QUEUES')
  460.         lpstat_pat = re.compile('^device for (.*): (.*)', re.IGNORECASE)
  461.         (status, output) = utils.run('lpstat -v')
  462.         log.info()
  463.         cups_printers = []
  464.         for p in output.splitlines():
  465.             
  466.             try:
  467.                 match = lpstat_pat.search(p)
  468.                 printer_name = match.group(1)
  469.                 device_uri = match.group(2)
  470.                 cups_printers.append((printer_name, device_uri))
  471.             continue
  472.             except AttributeError:
  473.                 continue
  474.             
  475.  
  476.         
  477.         log.debug(cups_printers)
  478.         if cups_printers:
  479.             non_hp = False
  480.             for p in cups_printers:
  481.                 (printer_name, device_uri) = p
  482.                 
  483.                 try:
  484.                     (back_end, is_hp, bus, model, serial, dev_file, host, port) = parseDeviceURI(device_uri)
  485.                 except Error:
  486.                     None<EXCEPTION MATCH>AttributeError
  487.                     None<EXCEPTION MATCH>AttributeError
  488.                     (back_end, is_hp, bus, model, serial, dev_file, host, port) = ('', False, '', '', '', '', '', 1)
  489.                 except:
  490.                     None<EXCEPTION MATCH>AttributeError
  491.  
  492.                 log.info(log.bold(printer_name))
  493.                 log.info(log.bold('-' * len(printer_name)))
  494.                 x = 'Unknown'
  495.                 if back_end == 'hpfax':
  496.                     x = 'Fax'
  497.                 elif back_end == 'hp':
  498.                     x = 'Printer'
  499.                 
  500.                 log.info('Type: %s' % x)
  501.                 if is_hp:
  502.                     x = 'Yes, using the %s: CUPS backend.' % back_end
  503.                 else:
  504.                     x = 'No, not using the hp: or hpfax: CUPS backend.'
  505.                     non_hp = True
  506.                 log.info('Installed in HPLIP?: %s' % x)
  507.                 log.info('Device URI: %s' % device_uri)
  508.                 ppd = os.path.join('/etc/cups/ppd', printer_name + '.ppd')
  509.                 if os.path.exists(ppd):
  510.                     log.info('PPD: %s' % ppd)
  511.                     nickname_pat = re.compile('\\*NickName:\\s*\\"(.*)"', re.MULTILINE)
  512.                     f = file(ppd, 'r').read(4096)
  513.                     
  514.                     try:
  515.                         desc = nickname_pat.search(f).group(1)
  516.                     except AttributeError:
  517.                         desc = ''
  518.  
  519.                     log.info('PPD Description: %s' % desc)
  520.                     (status, output) = utils.run('lpstat -p%s' % printer_name)
  521.                     log.info('Printer status: %s' % output.replace('\n', ''))
  522.                     if back_end == 'hpfax' and 'HP Fax' not in desc:
  523.                         num_errors += 1
  524.                         log.error("Incorrect PPD file for fax queue '%s'. Fax queues must use 'HP-Fax-hplip.ppd'." % printer_name)
  525.                     elif back_end == 'hp' and 'HP Fax' in desc:
  526.                         num_errors += 1
  527.                         log.error("Incorrect PPD file for a print queue '%s'. Print queues must not use 'HP-Fax-hplip.ppd'." % printer_name)
  528.                     elif back_end not in ('hp', 'hpfax'):
  529.                         log.warn('Printer is not HPLIP installed. Printers must use the hp: or hpfax: CUPS backend to function in HPLIP.')
  530.                         num_errors += 1
  531.                     
  532.                 
  533.                 if device_avail and is_hp:
  534.                     d = None
  535.                     
  536.                     try:
  537.                         d = device.Device(device_uri)
  538.                     except Error:
  539.                         log.error('Device initialization failed.')
  540.                         continue
  541.                     
  542.  
  543.                     plugin = d.mq.get('plugin', PLUGIN_NONE)
  544.                     if plugin in (PLUGIN_REQUIRED, PLUGIN_OPTIONAL):
  545.                         if core.check_for_plugin():
  546.                             if plugin == PLUGIN_REQUIRED:
  547.                                 log.info('Required plug-in status: Installed')
  548.                             else:
  549.                                 log.info('Optional plug-in status: Installed')
  550.                         else:
  551.                             num_errors += 1
  552.                             if plugin == PLUGIN_REQUIRED:
  553.                                 log.error('Required plug-in status: Not installed')
  554.                             else:
  555.                                 log.warn('Optional plug-in status: Not installed')
  556.                     
  557.                     if bus in ('par', 'usb'):
  558.                         
  559.                         try:
  560.                             d.open()
  561.                         except Error:
  562.                             e = None
  563.                             log.error(e.msg)
  564.                             deviceid = ''
  565.  
  566.                         deviceid = d.getDeviceID()
  567.                         log.debug(deviceid)
  568.                         if not deviceid:
  569.                             num_errors += 1
  570.                         else:
  571.                             log.info('Communication status: Good')
  572.                     elif bus == 'net':
  573.                         
  574.                         try:
  575.                             (error_code, deviceid) = d.getPML(pml.OID_DEVICE_ID)
  576.                         except Error:
  577.                             error_code = pml.ERROR_COMMAND_EXECUTION
  578.  
  579.                         if error_code > pml.ERROR_MAX_OK:
  580.                             num_errors += 1
  581.                         else:
  582.                             log.info('Communication status: Good')
  583.                     log.info()
  584.                     continue
  585.                 None if d is not None else bus in ('par', 'usb')
  586.             
  587.         else:
  588.             log.warn('No queues found.')
  589.         if scanning_enabled:
  590.             tui.header('SANE CONFIGURATION')
  591.             log.info(log.bold("'hpaio' in '/etc/sane.d/dll.conf'..."))
  592.             
  593.             try:
  594.                 f = file('/etc/sane.d/dll.conf', 'r')
  595.             except IOError:
  596.                 log.error("'/etc/sane.d/dll.conf' not found. Is SANE installed?")
  597.                 num_errors += 1
  598.  
  599.             found = False
  600.             for line in f:
  601.                 if 'hpaio' in line:
  602.                     found = True
  603.                     continue
  604.             
  605.             if not found:
  606.                 log.info(log.bold("'hpaio' in '/etc/sane.d/dll.d/hplip'..."))
  607.                 
  608.                 try:
  609.                     f = file('/etc/sane.d/dll.d/hplip', 'r')
  610.                 except IOError:
  611.                     log.error("'/etc/sane.d/dll.d/hplip' not found.")
  612.                     num_errors += 1
  613.  
  614.                 found = False
  615.                 for line in f:
  616.                     if 'hpaio' in line:
  617.                         found = True
  618.                         continue
  619.                 
  620.             
  621.             if found:
  622.                 log.info("OK, found. SANE backend 'hpaio' is properly set up.")
  623.             else:
  624.                 num_errors += 1
  625.                 log.error("Not found. SANE backend 'hpaio' NOT properly setup (needs to be added to /etc/sane.d/dll.conf).")
  626.             log.info()
  627.             log.info(log.bold("Checking output of 'scanimage -L'..."))
  628.             if utils.which('scanimage'):
  629.                 (status, output) = utils.run('scanimage -L')
  630.                 log.info(output)
  631.             else:
  632.                 log.error('scanimage not found.')
  633.         
  634.         tui.header('PYTHON EXTENSIONS')
  635.         log.info(log.bold("Checking 'cupsext' CUPS extension..."))
  636.         
  637.         try:
  638.             import cupsext
  639.         except ImportError:
  640.             num_errors += 1
  641.             log.error('NOT FOUND OR FAILED TO LOAD! Please reinstall HPLIP and check for the proper installation of cupsext.')
  642.  
  643.         log.info('OK, found.')
  644.         log.info()
  645.         log.info(log.bold("Checking 'pcardext' Photocard extension..."))
  646.         
  647.         try:
  648.             import pcardext
  649.         except ImportError:
  650.             num_errors += 1
  651.             log.error('NOT FOUND OR FAILED TO LOAD! Please reinstall HPLIP and check for the proper installation of pcardext.')
  652.  
  653.         log.info('OK, found.')
  654.         log.info()
  655.         log.info(log.bold("Checking 'hpmudext' I/O extension..."))
  656.         
  657.         try:
  658.             import hpmudext
  659.             hpmudext_avail = True
  660.         except ImportError:
  661.             hpmudext_avail = False
  662.             num_errors += 1
  663.             log.error('NOT FOUND OR FAILED TO LOAD! Please reinstall HPLIP and check for the proper installation of hpmudext.')
  664.  
  665.         log.info('OK, found.')
  666.         if scanning_enabled:
  667.             log.info()
  668.             log.info(log.bold("Checking 'scanext' SANE scanning extension..."))
  669.             
  670.             try:
  671.                 import scanext
  672.             except ImportError:
  673.                 num_errors += 1
  674.                 log.error('NOT FOUND OR FAILED TO LOAD! Please reinstall HPLIP and check for the proper installation of scanext.')
  675.  
  676.             log.info('OK, found.')
  677.             log.info()
  678.         
  679.         tui.header('USB I/O SETUP')
  680.         if hpmudext_avail:
  681.             lsusb = utils.which('lsusb')
  682.             if lsusb:
  683.                 log.info()
  684.                 log.info(log.bold('Checking for permissions of USB attached printers...'))
  685.                 lsusb = os.path.join(lsusb, 'lsusb')
  686.                 (status, output) = utils.run('%s -d03f0:' % lsusb)
  687.                 lsusb_pat = re.compile('^Bus\\s([0-9a-fA-F]{3,3})\\sDevice\\s([0-9a-fA-F]{3,3}):\\sID\\s([0-9a-fA-F]{4,4}):([0-9a-fA-F]{4,4})(.*)', re.IGNORECASE)
  688.                 log.debug(output)
  689.                 for o in output.splitlines():
  690.                     ok = True
  691.                     match = lsusb_pat.search(o)
  692.                     if match is not None:
  693.                         (bus, device, vid, pid, mfg) = match.groups()
  694.                         log.info('\nHP Device 0x%x at %s:%s: ' % (int(pid, 16), bus, device))
  695.                         (result_code, deviceuri) = hpmudext.make_usb_uri(bus, device)
  696.                         if result_code == hpmudext.HPMUD_R_OK:
  697.                             log.info('    Device URI: %s' % deviceuri)
  698.                         else:
  699.                             log.warn('    Device URI: (Makeuri FAILED)')
  700.                         devnode = os.path.join('/', 'dev', 'bus', 'usb', bus, device)
  701.                         if not os.path.exists(devnode):
  702.                             devnode = os.path.join('/', 'proc', 'bus', 'usb', bus, device)
  703.                         
  704.                         if os.path.exists(devnode):
  705.                             log.info('    Device node: %s' % devnode)
  706.                             (st_mode, st_ino, st_dev, st_nlink, st_uid, st_gid, st_size, st_atime, st_mtime, st_ctime) = os.stat(devnode)
  707.                             log.info('    Mode: 0%o' % (st_mode & 511))
  708.                             getfacl = utils.which('getfacl')
  709.                             if getfacl:
  710.                                 getfacl = os.path.join(getfacl, 'getfacl')
  711.                                 (status, output) = utils.run('%s %s' % (getfacl, devnode))
  712.                                 log.info(output)
  713.                             
  714.                         
  715.                     os.path.exists(devnode)
  716.                 
  717.             
  718.         
  719.     
  720.     tui.header('SUMMARY')
  721.     if num_errors:
  722.         if num_errors == 1:
  723.             log.error('1 error or warning.')
  724.         else:
  725.             log.error('%d errors and/or warnings.' % num_errors)
  726.         if overall_commands_to_run:
  727.             log.info()
  728.             log.info(log.bold('Summary of needed commands to run to satisfy missing dependencies:'))
  729.             for c in overall_commands_to_run:
  730.                 log.info(c)
  731.             
  732.         
  733.         log.info()
  734.         log.info('Please refer to the installation instructions at:')
  735.         log.info('http://hplip.sourceforge.net/install/index.html\n')
  736.     else:
  737.         log.info(log.green('No errors or warnings.'))
  738. except KeyboardInterrupt:
  739.     log.error('User exit')
  740.  
  741. log.info()
  742. log.info('Done.')
  743.